<template>
	<view class="coupon">
		<view class="h1">
			发票状态：<span>{{fa.statusName}}</span>
		</view>
		<view class="top">

			<view class="con">
				<view>
					订单状态：<span>已完成</span>
				</view>
				<view>
					订单编号：<span>{{cOrderNo}}</span>
				</view>

				<view>
					发票类型：<span>普通电子发票</span>
				</view>
				<view>
					发票内容：<span>商品明细</span>
				</view>
			</view>
			<view class="ca" @click="toSelect">
				<view class="">
					发票抬头：<span>{{dType}}</span>
				</view>
				<view class="">
					电话：<span>{{defaultData.mobile}}</span>
					<image src="../../static/img/1/1.png" mode="widthFix"></image>
				</view>
				<view class="bb">
					邮箱：<span>{{defaultData.email}}</span>
				</view>
			</view>
			<view class="sub" @click="sendData">
				申请开票
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				cOrderNo: '',
				fa: {},
				defaultData: '',
				iShopId:''
			}
		},
		onLoad(options) {

			this.cOrderNo = options.cOrderNo
			this.iShopId = options.iShopId
			this.getData()
		},
		computed: {
			dType: function() {
				if (this.defaultData.type == 2) {
					return "企业"
				} else {
					return "个人"
				}
			}
		},
		methods: {
			getData() {
				let that = this
				that.$Request.post(
					that.$api.httpApi.user.getEInvoice+'&token='+that.$SysCache.get('token')+'&orderNo='+this.cOrderNo+'&iShopId='+this.iShopId, {
						'orderNo': this.cOrderNo,
						iShopId:this.iShopId
					}
				).then(res => {
					if (res.code == 200) {
						that.fa = res.data;
					}
				});

				this.$Request.post4(
					this.$api.httpApi.user.getInvoiceList, {
						"uid": this.$SysCache.get('userInfo').id||this.$SysCache.get('userInfo').mid,
						"is_default": 1
					}
				).then(res => {
					if (res.code == 1) {
						this.defaultData = res.data[0]

					}
				})
			},
			sendData() {
				
				let that = this
				that.fa.title = this.defaultData.title
				that.fa.itin = this.defaultData.taxpayer_code
				that.fa.corpWholeName = this.defaultData.company_name
				that.fa.email = this.defaultData.email
				that.fa.phone = this.defaultData.mobile
				that.$Request.post(
					that.$api.httpApi.user.saveEInvoice+'&token='+this.$SysCache.get("token"),
					{"eInvoice":that.fa}
				).then(res => {
					if (res.code == 200) {

					}
				});
			},
			setData(item){
				let that = this
				that.$Request.post(
					that.$api.httpApi.user.getEInvoice, {
						'terminaltype': 'Mobile',
						'token': that.$SysCache.get('token'),
						'orderNo': this.cOrderNo
					}
				).then(res => {
					if (res.code == 200) {
						that.fa = res.data;
					}
				});
				this.defaultData = item
			},
			toSelect(){
				uni.navigateTo({
					url:`/pages/invoice/index?type=1`
				})
			}
		}



	}
</script>

<style lang="scss">
	.h1 {
		font-size: 26rpx;
		text-align: center;
		padding-top: 30rpx;

		span {
			font-size: 23upx;
			font-family: Microsoft YaHei;
			font-weight: 400;
			color: #DD524D;
		}
	}

	.top {
		width: 90%;
		margin: auto;
		padding-top: 30rpx;

		.sub {
			height: 80rpx;
			background-color: #007AFF;
			border-radius: 40rpx;
			text-align: center;
			font-size: 23upx;
			font-family: Microsoft YaHei;
			font-weight: 400;
			line-height: 80rpx;
			margin-top: 50rpx;
			color: #fff;
		}

		.ca {
			margin-top: 30rpx;

			view {
				font-size: 23rpx;
				color: #333;
				margin-bottom: 20rpx;

				image {
					display: inline-block;
					float: right;
					width: 12rpx;
					margin-top: 12rpx;
				}

				span {
					font-size: 22rpx;
					color: #666666;
				}
			}

			.bb {
				border-bottom: 1px solid #dfdfdf;
				padding-bottom: 10rpx;
			}
		}

		.con {
			border: 1px solid #dfdfdf;
			padding: 30rpx;
			border-radius: 18rpx;
			font-size: 23rpx;
			color: #333;

			span {
				font-size: 22rpx;
				color: #666666;
			}

			view {
				margin-bottom: 20rpx;
			}
		}

	}
</style>
